<?php
/*
 * @Descripttion: 
 * @Author: 夜雨
 * @Email: 448408740@qq.com
 * @Date: 2019-12-25 16:16:42
 * @LastEditTime : 2019-12-25 17:01:41
 */
	
require "auth.php";

if(!isset($_GET["token"]) || $_GET["token"] != "CRjAM61jieCidQPPtlf9"){
    echo '{"error":"参数有错误"}';
    die;
}
if(!isset($_GET["eqid"]) || $_GET["eqid"] == ''){
    echo '{"error":"参数有错误"}';
    die;
}
$eqid = $_GET["eqid"];

// 第一步：生成认证字符串

$ak = "3ada06d49eb34e67a0f1a6b025c52d7b";  // AccessKeyId
$sk = "c94794c73ee5411c9e577393645ebc32";  // SecretAccessKey
$method = "GET";
$host = "referer.bj.baidubce.com"; 
$uri = "/v1/eqid/".$eqid;   //输入EQID
$params = array(); 
date_default_timezone_set('UTC');
$timestamp = new \DateTime();
$expirationInSeconds = 60;
$authorization = generateAuthorization($ak, $sk, $method, $host, $uri, $params, $timestamp, $expirationInSeconds);
//print($authorization . "\n");


// 第二步：构造HTTP请求的header、body等信息

$url = "http://{$host}{$uri}";
//print_r($url."\n"."\n");
$timeStr = $timestamp->format("Y-m-d\TH:i:s\Z");
$head =  array(
    "Authorization: {$authorization}",
    "x-bce-date: {$timeStr}",
	"content-type:application/json"
);

$body = array();
$bodyStr = json_encode($body);


// 第三步：发送HTTP请求，并输出响应信息。
$curlp = curl_init();
curl_setopt($curlp, CURLOPT_POST, 1);
curl_setopt($curlp, CURLOPT_URL, $url);
curl_setopt($curlp, CURLOPT_HTTPHEADER, $head);
curl_setopt($curlp, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curlp, CURLOPT_POSTFIELDS, $bodyStr);
curl_setopt($curlp, CURLINFO_HEADER_OUT, 1);
curl_setopt($curlp, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curlp);
$request = curl_getinfo($curlp, CURLINFO_HEADER_OUT);
$status = curl_getinfo($curlp, CURLINFO_HTTP_CODE);
curl_close($curlp);
//print("request: {$request}\n");
//print("request body: {$bodyStr}\n");
//print("status: {$status}\n");
//print("response: {$response}\n");
print("{$response}");
?>
